import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Layouts

// TextField - IntValidator
Rectangle {
    Layout.fillWidth: true
    Layout.fillHeight: true

    Column {
        spacing: 20
        anchors.centerIn: parent
        width: parent.width * 0.8

        TextField {
            id: validatedField
            width: parent.width
            height: 30
            placeholderText: "请输入年龄(0-150)"

            // 背景框
            background: Rectangle {
                border.color: "#c0c0c0"
                border.width: 1
                radius: 4
            }

            validator: IntValidator {
                bottom: 0
                top: 150
            }

            onTextChanged: {
                if (acceptableInput) {
                    logText.text = "有效年龄:" + text;
                } else {
                    logText.text = "无效输入...";
                }
            }
        }

        Text {
            id: logText
            width: parent.width
            elide: Text.ElideRight
            color: validatedField.acceptableInput ? "green" : "red"
            font.pointSize: 10
        }
    }
}
